using System.Windows.Forms;
using CloudShot.Interfaces;

namespace CloudShot.Editor.Tools
{
  /// <summary>
  ///   Base class for all tools which create new graphic object
  /// </summary>
  internal abstract class ObjectTool : Tool
  {
    private readonly Section _changeToolsSection;
    private readonly Section _resetToolSection;
    private readonly Cursor _cursor;

    public override Cursor Cursor
    {
      get { return _cursor; }
    }

    protected ObjectTool(IDrawingCanvas canvas, Section changeToolsSection, Section resetToolSection, Cursor cursor) : base(canvas)
    {
      _changeToolsSection = changeToolsSection;
      _resetToolSection = resetToolSection;
      _cursor = cursor;
    }

    public override void OnMouseDown(MouseEventArgs e)
    {
      base.OnMouseDown(e);

      if (_changeToolsSection != null)
        _changeToolsSection.Enabled = false;
    }

    /// <summary>
    ///   Left mouse is released.
    ///   New object is created and resized.
    /// </summary>
    /// <param name="e"></param>
    public override void OnMouseUp(MouseEventArgs e)
    {
      base.OnMouseUp(e);

      if (_changeToolsSection != null)
        _changeToolsSection.Enabled = true;

      Canvas.CaptureMouse = false;
    }

    public override void Enter()
    {
      base.Enter();

      if (_resetToolSection != null)
        _resetToolSection.Enabled = true;
    }

    public override void Leave()
    {
      base.Leave();

      if (_resetToolSection != null)
        _resetToolSection.Enabled = false;

      if (_changeToolsSection != null)
        _changeToolsSection.Enabled = true;
    }
  }
}